name: E2E Tests
on:
  push:
    branches: [main]
  pull_request:
    paths:
      - "packages/create-llama/**"
      - ".github/workflows/e2e.yml"
    branches: [main]

env:
  POETRY_VERSION: "1.6.1"

jobs:
  e2e:
    name: create-llama
    timeout-minutes: 60
    strategy:
      fail-fast: true
      matrix:
        node-version: [18, 20]
        python-version: ["3.11"]
        os: [macos-latest, windows-latest]
    defaults:
      run:
        shell: bash
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - name: Set up python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install Poetry
        uses: snok/install-poetry@v1
        with:
          version: ${{ env.POETRY_VERSION }}
      - uses: pnpm/action-setup@v2
      - name: Setup Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: "pnpm"
      - name: Install dependencies
        run: pnpm install
      - name: Install Playwright Browsers
        run: pnpm exec playwright install --with-deps
        working-directory: ./packages/create-llama
      - name: Build create-llama
        run: pnpm run build
        working-directory: ./packages/create-llama
      - name: Pack
        run: pnpm pack --pack-destination ./output
        working-directory: ./packages/create-llama
      - name: Extract Pack
        run: tar -xvzf ./output/*.tgz -C ./output
        working-directory: ./packages/create-llama
      - name: Run Playwright tests
        run: pnpm exec playwright test
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
        working-directory: ./packages/create-llama
      - uses: actions/upload-artifact@v3
        if: always()
        with:
          name: playwright-report
          path: ./packages/create-llama/playwright-report/
          retention-days: 30
